{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "path = os.getcwd()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1  读取原始文件数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# 读取原始文件数据\n",
    "def load_csv():\n",
    "    train_agg = pd.read_csv(path + '/data/train/train_agg.csv', sep = '\\t')\n",
    "    train_log = pd.read_csv(path + '/data/train/train_log.csv', sep = '\\t')\n",
    "    train_flg = pd.read_csv(path + '/data/train/train_flg.csv', sep = '\\t')\n",
    "\n",
    "    test_agg = pd.read_csv(path + '/data/test/test_agg.csv', sep = '\\t')\n",
    "    test_log = pd.read_csv(path + '/data/test/test_log.csv', sep = '\\t')\n",
    "\n",
    "    return train_agg, train_log, train_flg, test_agg, test_log\n",
    "\n",
    "train_agg, train_log, train_flg, test_agg, test_log = load_csv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = len(list(set(np.array(train_log['USRID'])))) + len(list(set(np.array(test_log['USRID']))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2  主要从train_log、test_log中提取特征：构造特征提取数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 添加train_log、test_log的临时标签\n",
    "train_log['LABEL'] = 1\n",
    "test_log['LABEL'] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 4425232 entries, 0 to 891413\n",
      "Data columns (total 5 columns):\n",
      "USRID      int64\n",
      "EVT_LBL    object\n",
      "OCC_TIM    object\n",
      "TCH_TYP    int64\n",
      "LABEL      int64\n",
      "dtypes: int64(3), object(2)\n",
      "memory usage: 202.6+ MB\n"
     ]
    }
   ],
   "source": [
    "data = pd.concat([train_log, test_log], axis = 0)  # 按行合并\n",
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL</th>\n",
       "      <th>OCC_TIM</th>\n",
       "      <th>TCH_TYP</th>\n",
       "      <th>LABEL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10002</td>\n",
       "      <td>163-577-913</td>\n",
       "      <td>2018-03-22 16:31:44</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10002</td>\n",
       "      <td>163-578-914</td>\n",
       "      <td>2018-03-22 16:31:18</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10002</td>\n",
       "      <td>259-924-1525</td>\n",
       "      <td>2018-03-22 16:31:15</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10002</td>\n",
       "      <td>326-1040-1677</td>\n",
       "      <td>2018-03-06 12:08:51</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10002</td>\n",
       "      <td>326-1041-1678</td>\n",
       "      <td>2018-03-09 14:40:22</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID        EVT_LBL              OCC_TIM  TCH_TYP  LABEL\n",
       "0  10002    163-577-913  2018-03-22 16:31:44        0      1\n",
       "1  10002    163-578-914  2018-03-22 16:31:18        0      1\n",
       "2  10002   259-924-1525  2018-03-22 16:31:15        0      1\n",
       "3  10002  326-1040-1677  2018-03-06 12:08:51        0      1\n",
       "4  10002  326-1041-1678  2018-03-09 14:40:22        0      1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断 train_log、test_log 中是否有重合 USRID\n",
    "len(list(set(np.array(data['USRID'])))) == l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3  构造特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.1 清洗log文件中的'EVT_LBL'、'OCC_TIM'数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 点击模块划分\n",
    "data['EVT_LBL_1'] = data['EVT_LBL'].apply(lambda x: int(x.split('-')[0]))\n",
    "data['EVT_LBL_2'] = data['EVT_LBL'].apply(lambda x: int(x.split('-')[1]))\n",
    "data['EVT_LBL_3'] = data['EVT_LBL'].apply(lambda x: int(x.split('-')[2]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL</th>\n",
       "      <th>OCC_TIM</th>\n",
       "      <th>TCH_TYP</th>\n",
       "      <th>LABEL</th>\n",
       "      <th>EVT_LBL_1</th>\n",
       "      <th>EVT_LBL_2</th>\n",
       "      <th>EVT_LBL_3</th>\n",
       "      <th>DAY</th>\n",
       "      <th>HOUR</th>\n",
       "      <th>WEEK</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10002</td>\n",
       "      <td>163-577-913</td>\n",
       "      <td>2018-03-22 16:31:44</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>163</td>\n",
       "      <td>577</td>\n",
       "      <td>913</td>\n",
       "      <td>22</td>\n",
       "      <td>16</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10002</td>\n",
       "      <td>163-578-914</td>\n",
       "      <td>2018-03-22 16:31:18</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>163</td>\n",
       "      <td>578</td>\n",
       "      <td>914</td>\n",
       "      <td>22</td>\n",
       "      <td>16</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10002</td>\n",
       "      <td>259-924-1525</td>\n",
       "      <td>2018-03-22 16:31:15</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>259</td>\n",
       "      <td>924</td>\n",
       "      <td>1525</td>\n",
       "      <td>22</td>\n",
       "      <td>16</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10002</td>\n",
       "      <td>326-1040-1677</td>\n",
       "      <td>2018-03-06 12:08:51</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>326</td>\n",
       "      <td>1040</td>\n",
       "      <td>1677</td>\n",
       "      <td>6</td>\n",
       "      <td>12</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10002</td>\n",
       "      <td>326-1041-1678</td>\n",
       "      <td>2018-03-09 14:40:22</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>326</td>\n",
       "      <td>1041</td>\n",
       "      <td>1678</td>\n",
       "      <td>9</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID        EVT_LBL              OCC_TIM  TCH_TYP  LABEL  EVT_LBL_1  \\\n",
       "0  10002    163-577-913  2018-03-22 16:31:44        0      1        163   \n",
       "1  10002    163-578-914  2018-03-22 16:31:18        0      1        163   \n",
       "2  10002   259-924-1525  2018-03-22 16:31:15        0      1        259   \n",
       "3  10002  326-1040-1677  2018-03-06 12:08:51        0      1        326   \n",
       "4  10002  326-1041-1678  2018-03-09 14:40:22        0      1        326   \n",
       "\n",
       "   EVT_LBL_2  EVT_LBL_3  DAY  HOUR  WEEK  \n",
       "0        577        913   22    16     4  \n",
       "1        578        914   22    16     4  \n",
       "2        924       1525   22    16     4  \n",
       "3       1040       1677    6    12     2  \n",
       "4       1041       1678    9    14     2  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 触发时间划分：DAY、HOUR、WEEK\n",
    "\n",
    "# 获取一个月内星期数\n",
    "def get_week(day):\n",
    "    day = int(day)\n",
    "    if day >= 1 and day <= 4:\n",
    "        return 1\n",
    "    if day >= 4  and  day <= 11:\n",
    "        return 2\n",
    "    if day >= 12 and day <= 18:\n",
    "        return 3\n",
    "    if day >= 19 and day <= 25:\n",
    "        return 4\n",
    "    if day >= 26:\n",
    "        return 5\n",
    "\n",
    "data['DAY'] = data['OCC_TIM'].apply(lambda x: int(x[8 : 10]))\n",
    "data['HOUR'] = data['OCC_TIM'].apply(lambda x: int(x[11 : 13]))\n",
    "data['WEEK'] = data['DAY'].apply(get_week)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2 构造特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.1 每个用户触发时间对应日期总数，包含一天多次启动的重复日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>USER_TIM_COUNT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  USER_TIM_COUNT\n",
       "0      2               9\n",
       "1      3             157\n",
       "2      4              18\n",
       "3      5              20\n",
       "4      7              76"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature1 = data.groupby(['USRID'], as_index = False)['OCC_TIM'].agg({'USER_TIM_COUNT': 'count'})\n",
    "feature1.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.2 每个用户触发事件日期总数，不包含重复日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>USER_UNI_TIM_COUNT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  USER_UNI_TIM_COUNT\n",
       "0      2                   2\n",
       "1      3                   9\n",
       "2      4                   1\n",
       "3      5                   3\n",
       "4      7                   5"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature2 = data.groupby(['USRID'], as_index = False)['DAY'].agg({'USER_UNI_TIM_COUNT': 'nunique'})\n",
    "feature2.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.3 每个用户多天多次触发事件行为的统计量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\soft\\anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 48875 entries, 0 to 48874\n",
      "Data columns (total 2 columns):\n",
      "USRID    48875 non-null int64\n",
      "DAY      48875 non-null object\n",
      "dtypes: int64(1), object(1)\n",
      "memory usage: 763.8+ KB\n",
      "None\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>DAY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>13:13:13:14:13:13:13:13:13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>12:28:3:12:23:28:22:3:23:27:3:23:3:3:3:3:3:22:...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:2...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>20:13:20:13:20:20:5:20:13:20:13:20:13:13:20:20...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>9:9:20:21:24:21:21:9:21:9:21:21:20:28:9:21:9:2...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID                                                DAY\n",
       "0      2                         13:13:13:14:13:13:13:13:13\n",
       "1      3  12:28:3:12:23:28:22:3:23:27:3:23:3:3:3:3:3:22:...\n",
       "2      4  20:20:20:20:20:20:20:20:20:20:20:20:20:20:20:2...\n",
       "3      5  20:13:20:13:20:20:5:20:13:20:13:20:13:13:20:20...\n",
       "4      7  9:9:20:21:24:21:21:9:21:9:21:21:20:28:9:21:9:2..."
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature3 = data[['USRID', 'DAY']]\n",
    "feature3['DAY'] = feature3['DAY'].astype('str')\n",
    "feature3 = feature3.groupby(['USRID'])['DAY'].agg(lambda x: ':'.join(x)).reset_index()\n",
    "print(feature3.info())\n",
    "feature3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入统计分析包\n",
    "import scipy.stats as sp\n",
    "\n",
    "# 用户多天多次触发事件行为的统计量\n",
    "def get_time_gap(strs, parm):\n",
    "    time = strs.split(':')\n",
    "    time = list(set(time))\n",
    "    time = sorted(list(map(lambda x : int(x), time)), reverse = True)\n",
    "    time_gap = []\n",
    "    #用户只在当天活跃\n",
    "    if len(time) == 1:\n",
    "        return -1\n",
    "\n",
    "    for index, value in enumerate(time):\n",
    "        if index <= len(time) - 2:\n",
    "            # 获取启动相邻日期的间隔\n",
    "            gap = time[index] - time[index + 1]\n",
    "            time_gap.append(gap)\n",
    "\n",
    "    if parm == '1':    # 平均值\n",
    "        return np.mean(time_gap)\n",
    "    elif parm == '2':  # 最大值\n",
    "        return np.max(time_gap)\n",
    "    elif parm == '3':  # 最小值\n",
    "        return np.min(time_gap)\n",
    "    elif parm == '4':  # 标准差\n",
    "        return np.std(time_gap)\n",
    "    elif parm == '5':  # 峰度\n",
    "        return sp.stats.skew(time_gap)\n",
    "    elif parm == '6':  # 偏度\n",
    "        return sp.stats.kurtosis(time_gap)\n",
    "    \n",
    "# 均值\n",
    "feature3['TIME_GAP_MEAN'] = feature3['DAY'].apply(get_time_gap, args = ('1'))\n",
    "# 最大\n",
    "feature3['TIME_GAP_MAX'] = feature3['DAY'].apply(get_time_gap, args = ('2'))\n",
    "# 最小\n",
    "feature3['TIME_GAP_MIN'] = feature3['DAY'].apply(get_time_gap, args = ('3'))\n",
    "# 方差\n",
    "feature3['TIME_GAP_STD'] = feature3['DAY'].apply(get_time_gap, args = ('4'))\n",
    "# 锋度\n",
    "feature3['TIME_GAP_SKEW'] = feature3['DAY'].apply(get_time_gap, args = ('5'))\n",
    "# 偏度\n",
    "feature3['TIME_GAP_KURT'] = feature3['DAY'].apply(get_time_gap, args = ('6'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 日均行为次数\n",
    "feature3['ACT_DATE_MEAN'] = feature3['DAY'].apply(\n",
    "    lambda x: len(x.split(':')) / len(set(x.split(':')))\n",
    ")\n",
    "# 行为平均日期\n",
    "feature3['DATE_ACT_MEAN'] = feature3['DAY'].apply(\n",
    "    lambda x: np.sum([int(ele) for ele in x.split(':')]) / len(x.split(\":\"))\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入Counter工具用于支持便捷和快速地计数\n",
    "from collections import Counter\n",
    "\n",
    "# 用户是否当天有多次触发事件\n",
    "def cur_day_repeat_count(strs):\n",
    "    time = strs.split(':')\n",
    "    time = dict(Counter(time))  # 生成字典{key: value}：key为日期、value为日期出现次数\n",
    "    time = sorted(time.items(), key = lambda item: item[1], reverse = False)  # 按照value升序排序\n",
    "    # 一天一次触发事件\n",
    "    if (len(time) == 1) & (time[0][1] == 1):  # 只有一天触发事件，且当天 value == 1\n",
    "        return 0\n",
    "    # 一天多次触发事件\n",
    "    elif (len(time) == 1) & (time[0][1] > 1): # 只有一天触发事件，且当天 value > 1\n",
    "        return 1\n",
    "    # 多天多次触发事件\n",
    "    elif (len(time) > 1) & (time[0][1] == 1): # 多天触发事件，且第一次触发事件 value > 1\n",
    "        return 2\n",
    "    else:\n",
    "        return 3\n",
    "    \n",
    "# 用户是否当天有多次触发事件\n",
    "feature3['DATE_REPEAT_COUNT'] = feature3['DAY'].apply(cur_day_repeat_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 是否连续几天触发事件\n",
    "def get_continue_launch_count(strs, parm):\n",
    "    time = strs.split(':')\n",
    "    time = dict(Counter(time))\n",
    "    time = sorted(time.items(), key = lambda item: item[0], reverse = False)\n",
    "    key_list = []  # 日期升序\n",
    "    value_list = []\n",
    "    if len(time) == 1:  # 只有一天启动\n",
    "        return -2\n",
    "    for key, value in dict(time).items():\n",
    "        key_list.append(int(key))\n",
    "        value_list.append(int(value))\n",
    "\n",
    "    # 连续几天触发事件\n",
    "    if np.mean(np.diff(key_list, 1)) == 1:  # key值一阶差分\n",
    "        if parm == '1':\n",
    "            return np.mean(value_list)\n",
    "        elif parm == '2':\n",
    "            return np.max(value_list)\n",
    "        elif parm == '3':\n",
    "            return np.min(value_list)\n",
    "        elif parm == '4':\n",
    "            return np.sum(value_list)\n",
    "        elif parm == '5':\n",
    "            return np.std(value_list)\n",
    "    else:\n",
    "        return -1\n",
    "    \n",
    "feature3['ACT_COUNT_CON_DAY_MEAN'] = feature3['DAY'].apply(get_continue_launch_count, args = ('1'))\n",
    "feature3['ACT_COUNT_CON_DAY_MAX'] = feature3['DAY'].apply(get_continue_launch_count, args = ('2'))\n",
    "feature3['ACT_COUNT_CON_DAY_MIN'] = feature3['DAY'].apply(get_continue_launch_count, args = ('3'))\n",
    "feature3['ACT_COUNT_CON_DAY_SUM'] = feature3['DAY'].apply(get_continue_launch_count, args = ('4'))\n",
    "feature3['ACT_COUNT_CON_DAY_STD'] = feature3['DAY'].apply(get_continue_launch_count, args = ('5'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>TIME_GAP_MEAN</th>\n",
       "      <th>TIME_GAP_MAX</th>\n",
       "      <th>TIME_GAP_MIN</th>\n",
       "      <th>TIME_GAP_STD</th>\n",
       "      <th>TIME_GAP_SKEW</th>\n",
       "      <th>TIME_GAP_KURT</th>\n",
       "      <th>ACT_DATE_MEAN</th>\n",
       "      <th>DATE_ACT_MEAN</th>\n",
       "      <th>DATE_REPEAT_COUNT</th>\n",
       "      <th>ACT_COUNT_CON_DAY_MEAN</th>\n",
       "      <th>ACT_COUNT_CON_DAY_MAX</th>\n",
       "      <th>ACT_COUNT_CON_DAY_MIN</th>\n",
       "      <th>ACT_COUNT_CON_DAY_SUM</th>\n",
       "      <th>ACT_COUNT_CON_DAY_STD</th>\n",
       "      <th>ACT_COUNT_MAX</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>1.000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-3.000000</td>\n",
       "      <td>4.500000</td>\n",
       "      <td>13.111111</td>\n",
       "      <td>2</td>\n",
       "      <td>4.5</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>3.5</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>3.125</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>2.75851</td>\n",
       "      <td>1.763630</td>\n",
       "      <td>1.954901</td>\n",
       "      <td>17.444444</td>\n",
       "      <td>19.605096</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>-2.0</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>7.500</td>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>0.50000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-2.000000</td>\n",
       "      <td>6.666667</td>\n",
       "      <td>15.700000</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>4.750</td>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "      <td>3.76663</td>\n",
       "      <td>0.868396</td>\n",
       "      <td>-0.847173</td>\n",
       "      <td>15.200000</td>\n",
       "      <td>19.789474</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  TIME_GAP_MEAN  TIME_GAP_MAX  TIME_GAP_MIN  TIME_GAP_STD  \\\n",
       "0      2          1.000             1             1       0.00000   \n",
       "1      3          3.125            10             1       2.75851   \n",
       "2      4         -1.000            -1            -1      -1.00000   \n",
       "3      5          7.500             8             7       0.50000   \n",
       "4      7          4.750            11             1       3.76663   \n",
       "\n",
       "   TIME_GAP_SKEW  TIME_GAP_KURT  ACT_DATE_MEAN  DATE_ACT_MEAN  \\\n",
       "0       0.000000      -3.000000       4.500000      13.111111   \n",
       "1       1.763630       1.954901      17.444444      19.605096   \n",
       "2      -1.000000      -1.000000      18.000000      20.000000   \n",
       "3       0.000000      -2.000000       6.666667      15.700000   \n",
       "4       0.868396      -0.847173      15.200000      19.789474   \n",
       "\n",
       "   DATE_REPEAT_COUNT  ACT_COUNT_CON_DAY_MEAN  ACT_COUNT_CON_DAY_MAX  \\\n",
       "0                  2                     4.5                      8   \n",
       "1                  3                    -1.0                     -1   \n",
       "2                  1                    -2.0                     -2   \n",
       "3                  3                    -1.0                     -1   \n",
       "4                  3                    -1.0                     -1   \n",
       "\n",
       "   ACT_COUNT_CON_DAY_MIN  ACT_COUNT_CON_DAY_SUM  ACT_COUNT_CON_DAY_STD  \\\n",
       "0                      1                      9                    3.5   \n",
       "1                     -1                     -1                   -1.0   \n",
       "2                     -2                     -2                   -2.0   \n",
       "3                     -1                     -1                   -1.0   \n",
       "4                     -1                     -1                   -1.0   \n",
       "\n",
       "   ACT_COUNT_MAX  \n",
       "0            2.0  \n",
       "1            3.0  \n",
       "2           -1.0  \n",
       "3            NaN  \n",
       "4            2.0  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 连续触发事件最多天数\n",
    "def get_lianxu_day(day_list):\n",
    "    time = day_list.split(':')\n",
    "    time = list(map(lambda x : int(x), time))\n",
    "    m = np.array(time)\n",
    "    m = list(set(m))\n",
    "    if len(m) == 0:  # 无触发事件\n",
    "        return -30\n",
    "    if len(m) == 1:  # 只有一天触发事件\n",
    "        return -1\n",
    "    \n",
    "    n = np.where(np.diff(m) == 1)[0]  # 获取连续触发事件起始日期在m中的索引\n",
    "    i = 0\n",
    "    result = []\n",
    "    while i < len(n) - 1:\n",
    "        state = 1\n",
    "        while n[i + 1] - n[i] == 1:   # 连续触发事件起始日期连续时，state累加\n",
    "            state += 1\n",
    "            i += 1\n",
    "            if i == len(n) - 1:\n",
    "                break\n",
    "        if state == 1:\n",
    "            i += 1\n",
    "            result.append(2)\n",
    "        else:\n",
    "            i += 1\n",
    "            result.append(state + 1)\n",
    "    if len(n) == 1:\n",
    "        result.append(2)\n",
    "    if len(result) != 0:\n",
    "        return np.max(result)  # 输出最大连续触发事件天数\n",
    "\n",
    "feature3['ACT_COUNT_MAX'] = feature3['DAY'].apply(get_lianxu_day)\n",
    "del feature3['DAY']\n",
    "\n",
    "feature3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 48875 entries, 0 to 48874\n",
      "Data columns (total 16 columns):\n",
      "USRID                     48875 non-null int64\n",
      "TIME_GAP_MEAN             48875 non-null float64\n",
      "TIME_GAP_MAX              48875 non-null int64\n",
      "TIME_GAP_MIN              48875 non-null int64\n",
      "TIME_GAP_STD              48875 non-null float64\n",
      "TIME_GAP_SKEW             48875 non-null float64\n",
      "TIME_GAP_KURT             48875 non-null float64\n",
      "ACT_DATE_MEAN             48875 non-null float64\n",
      "DATE_ACT_MEAN             48875 non-null float64\n",
      "DATE_REPEAT_COUNT         48875 non-null int64\n",
      "ACT_COUNT_CON_DAY_MEAN    48875 non-null float64\n",
      "ACT_COUNT_CON_DAY_MAX     48875 non-null int64\n",
      "ACT_COUNT_CON_DAY_MIN     48875 non-null int64\n",
      "ACT_COUNT_CON_DAY_SUM     48875 non-null int64\n",
      "ACT_COUNT_CON_DAY_STD     48875 non-null float64\n",
      "ACT_COUNT_MAX             32018 non-null float64\n",
      "dtypes: float64(9), int64(7)\n",
      "memory usage: 6.0 MB\n"
     ]
    }
   ],
   "source": [
    "feature3.info()  # ACT_COUNT_MAX 属性有空值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.4 各用户点击各模块行为的发生天数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL_1_COUNT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  EVT_LBL_1_COUNT\n",
       "0      2                9\n",
       "1      3              157\n",
       "2      4               18\n",
       "3      5               20\n",
       "4      7               76"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature4 = data.groupby(['USRID'], as_index = False)['EVT_LBL_1'].agg({'EVT_LBL_1_COUNT': 'count'})\n",
    "feature5 = data.groupby(['USRID'], as_index = False)['EVT_LBL_2'].agg({'EVT_LBL_2_COUNT': 'count'})\n",
    "feature6 = data.groupby(['USRID'], as_index = False)['EVT_LBL_3'].agg({'EVT_LBL_3_COUNT': 'count'})\n",
    "feature4.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL_2_COUNT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  EVT_LBL_2_COUNT\n",
       "0      2                9\n",
       "1      3              157\n",
       "2      4               18\n",
       "3      5               20\n",
       "4      7               76"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature5.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL_3_COUNT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  EVT_LBL_3_COUNT\n",
       "0      2                9\n",
       "1      3              157\n",
       "2      4               18\n",
       "3      5               20\n",
       "4      7               76"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature6.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.5 判断时期是否为高峰日(周末)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\soft\\anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel_launcher.py:3: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>DAY</th>\n",
       "      <th>IS_HIGT_ACT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10002</td>\n",
       "      <td>22</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10003</td>\n",
       "      <td>21</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>10010</td>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>10014</td>\n",
       "      <td>26</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>1002</td>\n",
       "      <td>19</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    USRID  DAY  IS_HIGT_ACT\n",
       "0   10002   22            0\n",
       "10  10003   21            0\n",
       "30  10010   11            1\n",
       "36  10014   26            0\n",
       "37   1002   19            0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "higt_act_day_list = [3, 4, 10, 11, 17, 18, 24, 25]\n",
    "feature7 = data[['USRID', 'DAY']]\n",
    "feature7['IS_HIGT_ACT'] = feature7['DAY'].apply(lambda x: 1 if x in higt_act_day_list else 0)\n",
    "feature7 = feature7.drop_duplicates(subset = ['USRID'])\n",
    "feature7.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.6 用户每天启动次数统计量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>DAY</th>\n",
       "      <th>ACT_COUNT_PER_DAY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  DAY  ACT_COUNT_PER_DAY\n",
       "0      2   13                  8\n",
       "1      2   14                  1\n",
       "2      3    3                 24\n",
       "3      3    6                  8\n",
       "4      3    9                  6"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 各用户各日期启动次数\n",
    "feature8 = data.groupby(['USRID','DAY'], as_index = False)['TCH_TYP'].agg({'ACT_COUNT_PER_DAY': 'count'})\n",
    "feature8_copy = feature8.copy()\n",
    "\n",
    "# 用户平均每天启动次数\n",
    "feature9 = feature8_copy.groupby(['USRID'],as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_MEAN': 'mean'})\n",
    "# 用户启动次数最大值\n",
    "feature10 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_MAX': 'max'})\n",
    "# 用户启动次数最小值\n",
    "feature11 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_MIN': 'min'})\n",
    "# 用户每天启动次数的众值\n",
    "feature12 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_MODE': lambda x: x.value_counts().index[0]})\n",
    "# 方差\n",
    "feature13 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_STD': np.std})\n",
    "# 峰度\n",
    "feature14 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_SKEW': sp.stats.skew})\n",
    "# 偏度\n",
    "feature15 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_KURT': sp.stats.kurtosis})\n",
    "# 中位数\n",
    "feature16 = feature8_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_DAY'].agg({'ACT_COUNT_PER_DAY_MEDIAN': np.median})\n",
    "del feature8_copy\n",
    "\n",
    "feature8.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_MEAN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>4.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>17.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>6.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>15.200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_MEAN\n",
       "0      2                4.500000\n",
       "1      3               17.444444\n",
       "2      4               18.000000\n",
       "3      5                6.666667\n",
       "4      7               15.200000"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature9.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_MAX</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_MAX\n",
       "0      2                      8\n",
       "1      3                     30\n",
       "2      4                     18\n",
       "3      5                     10\n",
       "4      7                     32"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature10.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_MIN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_MIN\n",
       "0      2                      1\n",
       "1      3                      6\n",
       "2      4                     18\n",
       "3      5                      2\n",
       "4      7                      8"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature11.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_MODE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_MODE\n",
       "0      2                       1\n",
       "1      3                      25\n",
       "2      4                      18\n",
       "3      5                      10\n",
       "4      7                       8"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature12.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_STD</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>4.949747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>8.427798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>4.163332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>9.959920</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_STD\n",
       "0      2               4.949747\n",
       "1      3               8.427798\n",
       "2      4                    NaN\n",
       "3      5               4.163332\n",
       "4      7               9.959920"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature13.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_SKEW</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>-0.003637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>-0.528005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>1.121085</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_SKEW\n",
       "0      2                0.000000\n",
       "1      3               -0.003637\n",
       "2      4                0.000000\n",
       "3      5               -0.528005\n",
       "4      7                1.121085"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature14.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_KURT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>-2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>-1.386812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>-3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>-1.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>-0.296306</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_KURT\n",
       "0      2               -2.000000\n",
       "1      3               -1.386812\n",
       "2      4               -3.000000\n",
       "3      5               -1.500000\n",
       "4      7               -0.296306"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature15.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_DAY_MEDIAN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_DAY_MEDIAN\n",
       "0      2                       4.5\n",
       "1      3                      20.0\n",
       "2      4                      18.0\n",
       "3      5                       8.0\n",
       "4      7                      12.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature16.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.7 格式化时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\soft\\anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel_launcher.py:6: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>NEXT_TIME_MAX</th>\n",
       "      <th>NEXT_TIME_STD</th>\n",
       "      <th>NEXT_TIME_MEAN</th>\n",
       "      <th>NEXT_TIME_MIN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>71524.0</td>\n",
       "      <td>25265.607094</td>\n",
       "      <td>8995.125000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>837471.0</td>\n",
       "      <td>78473.735576</td>\n",
       "      <td>13918.692308</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>64.0</td>\n",
       "      <td>17.020101</td>\n",
       "      <td>10.941176</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>649940.0</td>\n",
       "      <td>202051.360194</td>\n",
       "      <td>67460.421053</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>959109.0</td>\n",
       "      <td>120814.312098</td>\n",
       "      <td>22041.040000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  NEXT_TIME_MAX  NEXT_TIME_STD  NEXT_TIME_MEAN  NEXT_TIME_MIN\n",
       "0      2        71524.0   25265.607094     8995.125000            0.0\n",
       "1      3       837471.0   78473.735576    13918.692308            0.0\n",
       "2      4           64.0      17.020101       10.941176            0.0\n",
       "3      5       649940.0  202051.360194    67460.421053            0.0\n",
       "4      7       959109.0  120814.312098    22041.040000            0.0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入时间模块\n",
    "import time\n",
    "import datetime\n",
    "\n",
    "feature17 = data[['USRID', 'OCC_TIM']]\n",
    "feature17['OCC_TIM'] = feature17['OCC_TIM'].apply(lambda x: time.mktime(time.strptime(x, \"%Y-%m-%d %H:%M:%S\")))\n",
    "\n",
    "log = feature17.sort_values(['USRID', 'OCC_TIM'])\n",
    "log['NEXT_TIME'] = log.groupby(['USRID'])['OCC_TIM'].diff(-1).apply(np.abs)\n",
    "log = log.groupby(['USRID'], as_index = False)['NEXT_TIME'].agg(\n",
    "    {\n",
    "        'NEXT_TIME_MEAN': np.mean,\n",
    "        'NEXT_TIME_STD': np.std,\n",
    "        'NEXT_TIME_MIN': np.min,\n",
    "        'NEXT_TIME_MAX': np.max\n",
    "    }\n",
    ")\n",
    "\n",
    "del feature17\n",
    "log.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.8 每周平均启动次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>WEEK</th>\n",
       "      <th>ACT_COUNT_PER_WEEK</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  WEEK  ACT_COUNT_PER_WEEK\n",
       "0      2     3                   9\n",
       "1      3     1                  24\n",
       "2      3     2                  14\n",
       "3      3     3                  12\n",
       "4      3     4                  32"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature18 = data.groupby(['USRID', 'WEEK'], as_index = False)['TCH_TYP'].agg({'ACT_COUNT_PER_WEEK': 'count'})\n",
    "feature18_copy = feature18.copy()\n",
    "feature18.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_MEAN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>31.400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>6.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>25.333333</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_MEAN\n",
       "0      2                 9.000000\n",
       "1      3                31.400000\n",
       "2      4                18.000000\n",
       "3      5                 6.666667\n",
       "4      7                25.333333"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用户平均每周启动次数\n",
    "feature19 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_MEAN': 'mean'})\n",
    "# 用户启动次数最大值\n",
    "feature20 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_MAX': 'max'})\n",
    "# 用户启动次数最小值\n",
    "feature21 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_MIN': 'min'})\n",
    "# 用户每周启动次数的众值\n",
    "feature22 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_MODE': lambda x: x.value_counts().index[0]})\n",
    "# 方差\n",
    "feature23 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_STD': np.std})\n",
    "# 峰度\n",
    "feature24 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_SKEW': sp.stats.skew})\n",
    "# 偏度\n",
    "feature25 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_KURT': sp.stats.kurtosis})\n",
    "# 中位数\n",
    "feature26 = feature18_copy.groupby(['USRID'], as_index = False)['ACT_COUNT_PER_WEEK'].agg({'ACT_COUNT_PER_WEEK_MEDIAN': np.median})\n",
    "del feature18_copy\n",
    "\n",
    "feature19.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_MAX</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_MAX\n",
       "0      2                       9\n",
       "1      3                      75\n",
       "2      4                      18\n",
       "3      5                      10\n",
       "4      7                      48"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature20.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_MIN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_MIN\n",
       "0      2                       9\n",
       "1      3                      12\n",
       "2      4                      18\n",
       "3      5                       2\n",
       "4      7                      12"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature21.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_MODE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_MODE\n",
       "0      2                        9\n",
       "1      3                       14\n",
       "2      4                       18\n",
       "3      5                       10\n",
       "4      7                       48"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature22.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_STD</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>25.667100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>4.163332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>19.731531</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_STD\n",
       "0      2                     NaN\n",
       "1      3               25.667100\n",
       "2      4                     NaN\n",
       "3      5                4.163332\n",
       "4      7               19.731531"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature23.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_SKEW</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>1.155548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>-0.528005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0.674555</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_SKEW\n",
       "0      2                 0.000000\n",
       "1      3                 1.155548\n",
       "2      4                 0.000000\n",
       "3      5                -0.528005\n",
       "4      7                 0.674555"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature24.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_KURT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>-3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>-0.227964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>-3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>-1.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>-1.500000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_KURT\n",
       "0      2                -3.000000\n",
       "1      3                -0.227964\n",
       "2      4                -3.000000\n",
       "3      5                -1.500000\n",
       "4      7                -1.500000"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature25.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>ACT_COUNT_PER_WEEK_MEDIAN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  ACT_COUNT_PER_WEEK_MEDIAN\n",
       "0      2                        9.0\n",
       "1      3                       24.0\n",
       "2      4                       18.0\n",
       "3      5                        8.0\n",
       "4      7                       16.0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature26.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.9 分析周末前两天启动统计特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 离周末越近，消费的可能性越大大，统计前2天与周末的特征\n",
    "stu_day_list = [3, 10, 17, 24]\n",
    "sun_day_list = [4, 11, 18, 25]\n",
    "before_day = []\n",
    "for i in stu_day_list:\n",
    "    if i - 2 > 0:\n",
    "        before_day.append(i - 2)\n",
    "        before_day.append(i - 1)\n",
    "        before_day.append(i)\n",
    "    elif i - 1 > 0:\n",
    "        before_day.append(i - 1)\n",
    "        before_day.append(i)\n",
    "    else:\n",
    "        before_day.append(i)\n",
    "for i in sun_day_list:\n",
    "    before_day.append(i)\n",
    "before_day.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "before_date = pd.DataFrame()\n",
    "for i in before_day:\n",
    "    before_date = pd.concat([before_date, data[data['DAY'] == int(i)]], axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>USER_TIM_COUNT_BEFORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  USER_TIM_COUNT_BEFORE\n",
       "0      3                     62\n",
       "1      7                     24\n",
       "2     11                     22\n",
       "3     12                     37\n",
       "4     13                     54"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "before_date_copy = before_date.copy()\n",
    "feature1_before = before_date_copy.groupby(['USRID'], as_index = False)['OCC_TIM'].agg({'USER_TIM_COUNT_BEFORE': 'count'})\n",
    "feature2_before = before_date_copy.groupby(['USRID'], as_index = False)['DAY'].agg({'USER_UNI_TIM_COUNT_BEFORE': 'nunique'})\n",
    "\n",
    "feature1_before.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>USER_UNI_TIM_COUNT_BEFORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  USER_UNI_TIM_COUNT_BEFORE\n",
       "0      3                          4\n",
       "1      7                          2\n",
       "2     11                          4\n",
       "3     12                          2\n",
       "4     13                          3"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature2_before.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\soft\\anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>TIME_GAP_MEAN_BEFORE</th>\n",
       "      <th>TIME_GAP_MAX_BEFORE</th>\n",
       "      <th>TIME_GAP_MIN_BEFORE</th>\n",
       "      <th>TIME_GAP_STD_BEFORE</th>\n",
       "      <th>TIME_GAP_SKEW_BEFORE</th>\n",
       "      <th>TIME_GAP_KURT_BEFORE</th>\n",
       "      <th>ACT_DATE_MEAN_BEFORE</th>\n",
       "      <th>DATE_ACT_MEAN_BEFORE</th>\n",
       "      <th>DATE_REPEAT_COUNT_BEFORE</th>\n",
       "      <th>ACT_COUNT_CON_DAY_MEAN_BEFORE</th>\n",
       "      <th>ACT_COUNT_CON_DAY_MAX_BEFORE</th>\n",
       "      <th>ACT_COUNT_CON_DAY_MIN_BEFORE</th>\n",
       "      <th>ACT_COUNT_CON_DAY_SUM_BEFORE</th>\n",
       "      <th>ACT_COUNT_CON_DAY_STD_BEFORE</th>\n",
       "      <th>ACT_COUNT_MAX_BEFORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>6.666667</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>4.921608</td>\n",
       "      <td>0.200700</td>\n",
       "      <td>-1.5</td>\n",
       "      <td>15.5</td>\n",
       "      <td>13.725806</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>14.000000</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>7.333333</td>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>0.471405</td>\n",
       "      <td>0.707107</td>\n",
       "      <td>-1.5</td>\n",
       "      <td>5.5</td>\n",
       "      <td>17.545455</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>18.5</td>\n",
       "      <td>4.783784</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>2.240741</td>\n",
       "      <td>3</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  TIME_GAP_MEAN_BEFORE  TIME_GAP_MAX_BEFORE  TIME_GAP_MIN_BEFORE  \\\n",
       "0      3              6.666667                   13                    1   \n",
       "1      7             15.000000                   15                   15   \n",
       "2     11              7.333333                    8                    7   \n",
       "3     12              6.000000                    6                    6   \n",
       "4     13              1.000000                    1                    1   \n",
       "\n",
       "   TIME_GAP_STD_BEFORE  TIME_GAP_SKEW_BEFORE  TIME_GAP_KURT_BEFORE  \\\n",
       "0             4.921608              0.200700                  -1.5   \n",
       "1             0.000000              0.000000                  -3.0   \n",
       "2             0.471405              0.707107                  -1.5   \n",
       "3             0.000000              0.000000                  -3.0   \n",
       "4             0.000000              0.000000                  -3.0   \n",
       "\n",
       "   ACT_DATE_MEAN_BEFORE  DATE_ACT_MEAN_BEFORE  DATE_REPEAT_COUNT_BEFORE  \\\n",
       "0                  15.5             13.725806                         3   \n",
       "1                  12.0             14.000000                         3   \n",
       "2                   5.5             17.545455                         3   \n",
       "3                  18.5              4.783784                         3   \n",
       "4                  18.0              2.240741                         3   \n",
       "\n",
       "   ACT_COUNT_CON_DAY_MEAN_BEFORE  ACT_COUNT_CON_DAY_MAX_BEFORE  \\\n",
       "0                           -1.0                            -1   \n",
       "1                           -1.0                            -1   \n",
       "2                           -1.0                            -1   \n",
       "3                           -1.0                            -1   \n",
       "4                           -1.0                            -1   \n",
       "\n",
       "   ACT_COUNT_CON_DAY_MIN_BEFORE  ACT_COUNT_CON_DAY_SUM_BEFORE  \\\n",
       "0                            -1                            -1   \n",
       "1                            -1                            -1   \n",
       "2                            -1                            -1   \n",
       "3                            -1                            -1   \n",
       "4                            -1                            -1   \n",
       "\n",
       "   ACT_COUNT_CON_DAY_STD_BEFORE  ACT_COUNT_MAX_BEFORE  \n",
       "0                          -1.0                   2.0  \n",
       "1                          -1.0                   NaN  \n",
       "2                          -1.0                   NaN  \n",
       "3                          -1.0                   NaN  \n",
       "4                          -1.0                   3.0  "
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature3_before = before_date_copy[['USRID', 'DAY']]\n",
    "feature3_before['DAY'] = feature3_before['DAY'].astype('str')\n",
    "feature3_before = feature3_before.groupby(['USRID'])['DAY'].agg(lambda x: ':'.join(x)).reset_index()\n",
    "\n",
    "# 用户是否多天有多次启动(均值)\n",
    "feature3_before['TIME_GAP_MEAN_BEFORE'] = feature3_before['DAY'].apply(get_time_gap, args = ('1'))\n",
    "# 最大\n",
    "feature3_before['TIME_GAP_MAX_BEFORE'] = feature3_before['DAY'].apply(get_time_gap, args = ('2'))\n",
    "# 最小\n",
    "feature3_before['TIME_GAP_MIN_BEFORE'] = feature3_before['DAY'].apply(get_time_gap, args = ('3'))\n",
    "# 方差\n",
    "feature3_before['TIME_GAP_STD_BEFORE'] = feature3_before['DAY'].apply(get_time_gap, args = ('4'))\n",
    "# 锋度\n",
    "feature3_before['TIME_GAP_SKEW_BEFORE'] = feature3_before['DAY'].apply(get_time_gap, args = ('5'))\n",
    "# 偏度\n",
    "feature3_before['TIME_GAP_KURT_BEFORE'] = feature3_before['DAY'].apply(get_time_gap, args = ('6'))\n",
    "\n",
    "# 平均行为次数\n",
    "feature3_before['ACT_DATE_MEAN_BEFORE'] = feature3_before['DAY'].apply(lambda x: len(x.split(':')) / len(set(x.split(':'))))\n",
    "# 平均行为日期\n",
    "feature3_before['DATE_ACT_MEAN_BEFORE'] = feature3_before['DAY'].apply(lambda x: np.sum([int(ele) for ele in x.split(':')]) / len(x.split(':')))\n",
    "# 用户是否当天有多次启动\n",
    "feature3_before['DATE_REPEAT_COUNT_BEFORE'] = feature3_before['DAY'].apply(cur_day_repeat_count)\n",
    "# 连续几天启动次数的均值，\n",
    "feature3_before['ACT_COUNT_CON_DAY_MEAN_BEFORE'] = feature3_before['DAY'].apply(get_continue_launch_count, args = ('1'))\n",
    "# 最大值，\n",
    "feature3_before['ACT_COUNT_CON_DAY_MAX_BEFORE'] = feature3_before['DAY'].apply(get_continue_launch_count, args = ('2'))\n",
    "# 最小值\n",
    "feature3_before['ACT_COUNT_CON_DAY_MIN_BEFORE'] = feature3_before['DAY'].apply(get_continue_launch_count, args = ('3'))\n",
    "# 次数\n",
    "feature3_before['ACT_COUNT_CON_DAY_SUM_BEFORE'] = feature3_before['DAY'].apply(get_continue_launch_count, args = ('4'))\n",
    "# 方差\n",
    "feature3_before['ACT_COUNT_CON_DAY_STD_BEFORE'] = feature3_before['DAY'].apply(get_continue_launch_count, args = ('5'))\n",
    "\n",
    "feature3_before['ACT_COUNT_MAX_BEFORE'] = feature3_before['DAY'].apply(get_lianxu_day)\n",
    "del feature3_before['DAY']\n",
    "\n",
    "feature3_before.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL_1_COUNT_BEFORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  EVT_LBL_1_COUNT_BEFORE\n",
       "0      3                      62\n",
       "1      7                      24\n",
       "2     11                      22\n",
       "3     12                      37\n",
       "4     13                      54"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用户发生行为的天数\n",
    "feature4_before = before_date.groupby(['USRID'], as_index = False)['EVT_LBL_1'].agg({'EVT_LBL_1_COUNT_BEFORE': 'count'})\n",
    "feature5_before = before_date.groupby(['USRID'], as_index = False)['EVT_LBL_2'].agg({'EVT_LBL_2_COUNT_BEFORE': 'count'})\n",
    "feature6_before = before_date.groupby(['USRID'], as_index = False)['EVT_LBL_3'].agg({'EVT_LBL_3_COUNT_BEFORE': 'count'})\n",
    "\n",
    "feature4_before.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL_2_COUNT_BEFORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  EVT_LBL_2_COUNT_BEFORE\n",
       "0      3                      62\n",
       "1      7                      24\n",
       "2     11                      22\n",
       "3     12                      37\n",
       "4     13                      54"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature5_before.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>EVT_LBL_3_COUNT_BEFORE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  EVT_LBL_3_COUNT_BEFORE\n",
       "0      3                      62\n",
       "1      7                      24\n",
       "2     11                      22\n",
       "3     12                      37\n",
       "4     13                      54"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature6_before.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "del before_date\n",
    "del before_date_copy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2.10 交叉表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>TCH_TYP</th>\n",
       "      <th>USRID</th>\n",
       "      <th>0</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>157</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "TCH_TYP  USRID    0  2\n",
       "0            2    9  0\n",
       "1            3  157  0\n",
       "2            4   18  0\n",
       "3            5   20  0\n",
       "4            7   76  0"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature27 = pd.crosstab(data['USRID'], data['TCH_TYP']).reset_index()\n",
    "feature28 = pd.crosstab(data['USRID'], data['EVT_LBL_1']).reset_index()\n",
    "feature29 = pd.crosstab(data['USRID'], data['EVT_LBL_2']).reset_index()\n",
    "feature30 = pd.crosstab(data['USRID'], data['EVT_LBL_3']).reset_index()\n",
    "feature31 = pd.crosstab(data['USRID'], data['HOUR']).reset_index()\n",
    "feature32 = pd.crosstab(data['USRID'], data['WEEK']).reset_index()\n",
    "\n",
    "feature27.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>EVT_LBL_1</th>\n",
       "      <th>USRID</th>\n",
       "      <th>0</th>\n",
       "      <th>10</th>\n",
       "      <th>38</th>\n",
       "      <th>102</th>\n",
       "      <th>139</th>\n",
       "      <th>162</th>\n",
       "      <th>163</th>\n",
       "      <th>181</th>\n",
       "      <th>257</th>\n",
       "      <th>...</th>\n",
       "      <th>359</th>\n",
       "      <th>372</th>\n",
       "      <th>396</th>\n",
       "      <th>438</th>\n",
       "      <th>460</th>\n",
       "      <th>508</th>\n",
       "      <th>518</th>\n",
       "      <th>520</th>\n",
       "      <th>540</th>\n",
       "      <th>604</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>16</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>33</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "EVT_LBL_1  USRID   0  10  38  102  139  162  163  181  257 ...   359  372  \\\n",
       "0              2   1   0   1    0    0    0    0    0    0 ...     3    0   \n",
       "1              3  12   0   8    0    3    0    0    0    3 ...    16    2   \n",
       "2              4   1   0   1    0    0    0    0    0    0 ...     1    0   \n",
       "3              5   2   0   3    0    0    0    0    0    0 ...     2    0   \n",
       "4              7   6   0   6    0    0    0    0    0    2 ...     6    0   \n",
       "\n",
       "EVT_LBL_1  396  438  460  508  518  520  540  604  \n",
       "0            0    0    0    0    0    1    0    0  \n",
       "1            4    0    0    0    0   33    6    7  \n",
       "2            0    0    0    0    0    3    0    0  \n",
       "3            0    0    0    0    0    3    0    0  \n",
       "4            0    0    0    0    0    6    0    0  \n",
       "\n",
       "[5 rows x 22 columns]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature28.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>EVT_LBL_2</th>\n",
       "      <th>USRID</th>\n",
       "      <th>14</th>\n",
       "      <th>15</th>\n",
       "      <th>16</th>\n",
       "      <th>17</th>\n",
       "      <th>18</th>\n",
       "      <th>19</th>\n",
       "      <th>20</th>\n",
       "      <th>21</th>\n",
       "      <th>22</th>\n",
       "      <th>...</th>\n",
       "      <th>2158</th>\n",
       "      <th>2159</th>\n",
       "      <th>2160</th>\n",
       "      <th>2161</th>\n",
       "      <th>2162</th>\n",
       "      <th>2163</th>\n",
       "      <th>2164</th>\n",
       "      <th>2165</th>\n",
       "      <th>2166</th>\n",
       "      <th>2167</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 179 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "EVT_LBL_2  USRID  14  15  16  17  18  19  20  21  22  ...   2158  2159  2160  \\\n",
       "0              2   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "1              3   0   0   0   0   0   0   0   0   0  ...      3     0     0   \n",
       "2              4   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "3              5   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "4              7   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "\n",
       "EVT_LBL_2  2161  2162  2163  2164  2165  2166  2167  \n",
       "0             0     0     0     0     0     0     0  \n",
       "1             0     0     0     0     1     0     0  \n",
       "2             0     0     0     0     0     0     0  \n",
       "3             0     0     0     0     0     0     0  \n",
       "4             0     0     0     0     0     0     0  \n",
       "\n",
       "[5 rows x 179 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature29.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>EVT_LBL_3</th>\n",
       "      <th>USRID</th>\n",
       "      <th>14</th>\n",
       "      <th>15</th>\n",
       "      <th>16</th>\n",
       "      <th>17</th>\n",
       "      <th>18</th>\n",
       "      <th>19</th>\n",
       "      <th>20</th>\n",
       "      <th>21</th>\n",
       "      <th>22</th>\n",
       "      <th>...</th>\n",
       "      <th>4389</th>\n",
       "      <th>4390</th>\n",
       "      <th>4391</th>\n",
       "      <th>4392</th>\n",
       "      <th>4393</th>\n",
       "      <th>4394</th>\n",
       "      <th>4395</th>\n",
       "      <th>4396</th>\n",
       "      <th>4397</th>\n",
       "      <th>4398</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 617 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "EVT_LBL_3  USRID  14  15  16  17  18  19  20  21  22  ...   4389  4390  4391  \\\n",
       "0              2   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "1              3   0   0   0   0   0   0   0   0   0  ...      0     1     0   \n",
       "2              4   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "3              5   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "4              7   0   0   0   0   0   0   0   0   0  ...      0     0     0   \n",
       "\n",
       "EVT_LBL_3  4392  4393  4394  4395  4396  4397  4398  \n",
       "0             0     0     0     0     0     0     0  \n",
       "1             0     0     0     0     0     0     0  \n",
       "2             0     0     0     0     0     0     0  \n",
       "3             0     0     0     0     0     0     0  \n",
       "4             0     0     0     0     0     0     0  \n",
       "\n",
       "[5 rows x 617 columns]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature30.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>HOUR</th>\n",
       "      <th>USRID</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>...</th>\n",
       "      <th>14</th>\n",
       "      <th>15</th>\n",
       "      <th>16</th>\n",
       "      <th>17</th>\n",
       "      <th>18</th>\n",
       "      <th>19</th>\n",
       "      <th>20</th>\n",
       "      <th>21</th>\n",
       "      <th>22</th>\n",
       "      <th>23</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>0</td>\n",
       "      <td>15</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>36</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "HOUR  USRID  0  1  2  3  4  5  6  7   8 ...  14  15  16  17  18  19  20  21  \\\n",
       "0         2  0  0  0  0  0  0  0  0   0 ...   0   0   0   0   0   1   0   0   \n",
       "1         3  0  0  0  0  0  0  0  0   0 ...   0  21   0  15   0   0  16   6   \n",
       "2         4  0  0  0  0  0  0  0  0   0 ...   0   0   0   0   0   0   0   0   \n",
       "3         5  0  0  0  0  0  0  0  0   0 ...   0   0  10   0   0   0   2   0   \n",
       "4         7  0  0  0  0  0  0  0  0  36 ...   0   0   0   0   0   0   0   0   \n",
       "\n",
       "HOUR  22  23  \n",
       "0      0   8  \n",
       "1      0   0  \n",
       "2      0   0  \n",
       "3      0   0  \n",
       "4      0   0  \n",
       "\n",
       "[5 rows x 25 columns]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature31.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>WEEK</th>\n",
       "      <th>USRID</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>24</td>\n",
       "      <td>14</td>\n",
       "      <td>12</td>\n",
       "      <td>32</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>16</td>\n",
       "      <td>0</td>\n",
       "      <td>48</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "WEEK  USRID   1   2   3   4   5\n",
       "0         2   0   0   9   0   0\n",
       "1         3  24  14  12  32  75\n",
       "2         4   0   0   0  18   0\n",
       "3         5   0   2   8  10   0\n",
       "4         7   0  16   0  48  12"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature32.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4 汇总特征数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>LABEL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10002</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10003</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>10010</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>10014</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>1002</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    USRID  LABEL\n",
       "0   10002      1\n",
       "10  10003      1\n",
       "30  10010      1\n",
       "36  10014      1\n",
       "37   1002      1"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = data[['USRID', 'LABEL']]\n",
    "data = data.drop_duplicates(subset = 'USRID')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 每天的平均消费次数统计量\n",
    "data = pd.merge(data, feature1, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature2, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature3, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature4, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature5, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature6, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature7, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature8, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature9, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature10, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature11, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature12, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature13, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature14, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature15, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature16, on = ['USRID'], how = 'left')\n",
    "\n",
    "# 各用户下一次启动APP与本次的时间间隔统计量\n",
    "data = pd.merge(data, log, on = ['USRID'], how = 'left')\n",
    "\n",
    "# 每周的平均消费次数统计量\n",
    "data = pd.merge(data, feature18, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature19, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature20, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature21, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature22, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature23, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature24, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature25, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature26, on = ['USRID'], how = 'left')\n",
    "\n",
    "# 周末及前两天启动统计特征\n",
    "data = pd.merge(data, feature1_before, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature2_before, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature3_before, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature4_before, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature5_before, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature6_before, on = ['USRID'], how = 'left')\n",
    "\n",
    "# 交叉表\n",
    "data = pd.merge(data, feature27, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature28, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature29, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature30, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature31, on = ['USRID'], how = 'left')\n",
    "data = pd.merge(data, feature32, on = ['USRID'], how = 'left')\n",
    "\n",
    "data = data.drop(['DAY_y'], axis = 1)\n",
    "data = data.rename(columns =  {'DAY_x': 'DAY'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "USRID\n",
      "LABEL\n",
      "USER_TIM_COUNT\n",
      "USER_UNI_TIM_COUNT\n",
      "TIME_GAP_MEAN\n",
      "TIME_GAP_MAX\n",
      "TIME_GAP_MIN\n",
      "TIME_GAP_STD\n",
      "TIME_GAP_SKEW\n",
      "TIME_GAP_KURT\n",
      "ACT_DATE_MEAN\n",
      "DATE_ACT_MEAN\n",
      "DATE_REPEAT_COUNT\n",
      "ACT_COUNT_CON_DAY_MEAN\n",
      "ACT_COUNT_CON_DAY_MAX\n",
      "ACT_COUNT_CON_DAY_MIN\n",
      "ACT_COUNT_CON_DAY_SUM\n",
      "ACT_COUNT_CON_DAY_STD\n",
      "ACT_COUNT_MAX\n",
      "EVT_LBL_1_COUNT\n",
      "EVT_LBL_2_COUNT\n",
      "EVT_LBL_3_COUNT\n",
      "DAY\n",
      "IS_HIGT_ACT\n",
      "ACT_COUNT_PER_DAY\n",
      "ACT_COUNT_PER_DAY_MEAN\n",
      "ACT_COUNT_PER_DAY_MAX\n",
      "ACT_COUNT_PER_DAY_MIN\n",
      "ACT_COUNT_PER_DAY_MODE\n",
      "ACT_COUNT_PER_DAY_STD\n",
      "ACT_COUNT_PER_DAY_SKEW\n",
      "ACT_COUNT_PER_DAY_KURT\n",
      "ACT_COUNT_PER_DAY_MEDIAN\n",
      "NEXT_TIME_MAX\n",
      "NEXT_TIME_STD\n",
      "NEXT_TIME_MEAN\n",
      "NEXT_TIME_MIN\n",
      "WEEK\n",
      "ACT_COUNT_PER_WEEK\n",
      "ACT_COUNT_PER_WEEK_MEAN\n",
      "ACT_COUNT_PER_WEEK_MAX\n",
      "ACT_COUNT_PER_WEEK_MIN\n",
      "ACT_COUNT_PER_WEEK_MODE\n",
      "ACT_COUNT_PER_WEEK_STD\n",
      "ACT_COUNT_PER_WEEK_SKEW\n",
      "ACT_COUNT_PER_WEEK_KURT\n",
      "ACT_COUNT_PER_WEEK_MEDIAN\n",
      "USER_TIM_COUNT_BEFORE\n",
      "USER_UNI_TIM_COUNT_BEFORE\n",
      "TIME_GAP_MEAN_BEFORE\n",
      "TIME_GAP_MAX_BEFORE\n",
      "TIME_GAP_MIN_BEFORE\n",
      "TIME_GAP_STD_BEFORE\n",
      "TIME_GAP_SKEW_BEFORE\n",
      "TIME_GAP_KURT_BEFORE\n",
      "ACT_DATE_MEAN_BEFORE\n",
      "DATE_ACT_MEAN_BEFORE\n",
      "DATE_REPEAT_COUNT_BEFORE\n",
      "ACT_COUNT_CON_DAY_MEAN_BEFORE\n",
      "ACT_COUNT_CON_DAY_MAX_BEFORE\n",
      "ACT_COUNT_CON_DAY_MIN_BEFORE\n",
      "ACT_COUNT_CON_DAY_SUM_BEFORE\n",
      "ACT_COUNT_CON_DAY_STD_BEFORE\n",
      "ACT_COUNT_MAX_BEFORE\n",
      "EVT_LBL_1_COUNT_BEFORE\n",
      "EVT_LBL_2_COUNT_BEFORE\n",
      "EVT_LBL_3_COUNT_BEFORE\n",
      "0_x\n",
      "2_x\n",
      "0_y\n",
      "10_x\n",
      "38\n",
      "102\n",
      "139\n",
      "162\n",
      "163\n",
      "181\n",
      "257\n",
      "259\n",
      "326\n",
      "359\n",
      "372\n",
      "396\n",
      "438\n",
      "460\n",
      "508\n",
      "518\n",
      "520\n",
      "540\n",
      "604\n",
      "14_x\n",
      "15_x\n",
      "16_x\n",
      "17_x\n",
      "18_x\n",
      "19_x\n",
      "20_x\n",
      "21_x\n",
      "22_x\n",
      "23_x\n",
      "43_x\n",
      "115\n",
      "221\n",
      "222\n",
      "223\n",
      "224\n",
      "225\n",
      "226\n",
      "227\n",
      "228\n",
      "229\n",
      "230\n",
      "231\n",
      "232\n",
      "233\n",
      "314\n",
      "392\n",
      "393\n",
      "394\n",
      "395\n",
      "553\n",
      "555\n",
      "557\n",
      "561_x\n",
      "569_x\n",
      "574\n",
      "575\n",
      "576\n",
      "577\n",
      "578\n",
      "701\n",
      "702\n",
      "703\n",
      "704\n",
      "705\n",
      "706\n",
      "922\n",
      "924\n",
      "1040\n",
      "1041\n",
      "1042\n",
      "1043\n",
      "1044\n",
      "1045\n",
      "1046\n",
      "1047\n",
      "1048\n",
      "1049\n",
      "1233\n",
      "1234\n",
      "1235\n",
      "1260\n",
      "1261\n",
      "1262\n",
      "1263\n",
      "1264\n",
      "1265\n",
      "1266\n",
      "1267\n",
      "1268\n",
      "1269\n",
      "1270\n",
      "1349\n",
      "1350\n",
      "1351\n",
      "1352\n",
      "1479\n",
      "1480\n",
      "1481\n",
      "1482\n",
      "1483\n",
      "1484\n",
      "1588\n",
      "1589\n",
      "1590\n",
      "1591\n",
      "1592\n",
      "1593\n",
      "1795\n",
      "1796\n",
      "1797\n",
      "1798\n",
      "1799\n",
      "1826\n",
      "1827\n",
      "1828\n",
      "1829\n",
      "1830\n",
      "1831\n",
      "1834\n",
      "1836\n",
      "1837\n",
      "1838\n",
      "1839\n",
      "1840\n",
      "1841\n",
      "1842\n",
      "1843\n",
      "1844\n",
      "1845\n",
      "1846\n",
      "1847\n",
      "1848\n",
      "1849\n",
      "1850\n",
      "1851\n",
      "1852\n",
      "1853\n",
      "1854\n",
      "1855\n",
      "1856\n",
      "1857\n",
      "1858\n",
      "1859\n",
      "1860\n",
      "1861\n",
      "1862\n",
      "1863\n",
      "1864\n",
      "1865\n",
      "1866\n",
      "1905\n",
      "1906\n",
      "1907\n",
      "1908\n",
      "1909\n",
      "1910\n",
      "1911\n",
      "1912\n",
      "1913\n",
      "1914\n",
      "1915\n",
      "1916\n",
      "2133\n",
      "2134\n",
      "2135\n",
      "2136\n",
      "2137\n",
      "2138\n",
      "2139\n",
      "2140\n",
      "2141\n",
      "2142\n",
      "2143\n",
      "2144\n",
      "2145\n",
      "2146\n",
      "2147\n",
      "2148\n",
      "2149\n",
      "2150\n",
      "2151\n",
      "2152\n",
      "2153\n",
      "2154\n",
      "2155\n",
      "2156\n",
      "2157\n",
      "2158\n",
      "2159\n",
      "2160\n",
      "2161\n",
      "2162\n",
      "2163\n",
      "2164\n",
      "2165\n",
      "2166\n",
      "2167\n",
      "14_y\n",
      "15_y\n",
      "16_y\n",
      "17_y\n",
      "18_y\n",
      "19_y\n",
      "20_y\n",
      "21_y\n",
      "22_y\n",
      "23_y\n",
      "43_y\n",
      "117\n",
      "267\n",
      "268\n",
      "269\n",
      "270\n",
      "271\n",
      "272\n",
      "273\n",
      "274\n",
      "275\n",
      "276\n",
      "277\n",
      "278\n",
      "279\n",
      "280\n",
      "281\n",
      "282\n",
      "283\n",
      "284\n",
      "285\n",
      "286\n",
      "290\n",
      "291\n",
      "462\n",
      "558\n",
      "559\n",
      "560\n",
      "561_y\n",
      "562\n",
      "563\n",
      "564\n",
      "565\n",
      "566\n",
      "567\n",
      "568\n",
      "569_y\n",
      "570\n",
      "571\n",
      "572\n",
      "573\n",
      "889\n",
      "891\n",
      "893\n",
      "897\n",
      "905\n",
      "910\n",
      "911\n",
      "912\n",
      "913\n",
      "914\n",
      "1196\n",
      "1197\n",
      "1198\n",
      "1199\n",
      "1200\n",
      "1201\n",
      "1523\n",
      "1525\n",
      "1677\n",
      "1678\n",
      "1679\n",
      "1680\n",
      "1681\n",
      "1682\n",
      "1683\n",
      "1684\n",
      "1685\n",
      "1686\n",
      "1687\n",
      "1688\n",
      "1689\n",
      "1690\n",
      "1691\n",
      "1692\n",
      "1693\n",
      "1694\n",
      "1695\n",
      "1696\n",
      "1697\n",
      "1698\n",
      "1699\n",
      "1700\n",
      "1701\n",
      "1702\n",
      "1703\n",
      "1704\n",
      "1705\n",
      "1706\n",
      "1707\n",
      "1708\n",
      "1709\n",
      "1710\n",
      "1711\n",
      "1712\n",
      "1713\n",
      "1714\n",
      "1715\n",
      "1716\n",
      "1717\n",
      "1718\n",
      "1719\n",
      "1720\n",
      "1722\n",
      "1723\n",
      "1724\n",
      "1725\n",
      "1726\n",
      "1727\n",
      "1728\n",
      "1729\n",
      "2003\n",
      "2004\n",
      "2005\n",
      "2031\n",
      "2032\n",
      "2033\n",
      "2034\n",
      "2035\n",
      "2036\n",
      "2037\n",
      "2039\n",
      "2040\n",
      "2041\n",
      "2042\n",
      "2043\n",
      "2044\n",
      "2045\n",
      "2046\n",
      "2047\n",
      "2048\n",
      "2049\n",
      "2050\n",
      "2051\n",
      "2052\n",
      "2053\n",
      "2054\n",
      "2055\n",
      "2056\n",
      "2057\n",
      "2058\n",
      "2059\n",
      "2061\n",
      "2062\n",
      "2063\n",
      "2064\n",
      "2065\n",
      "2066\n",
      "2067\n",
      "2068\n",
      "2069\n",
      "2070\n",
      "2071\n",
      "2072\n",
      "2073\n",
      "2074\n",
      "2075\n",
      "2076\n",
      "2077\n",
      "2078\n",
      "2079\n",
      "2080\n",
      "2204\n",
      "2205\n",
      "2206\n",
      "2207\n",
      "2637\n",
      "2638\n",
      "2639\n",
      "2640\n",
      "2641\n",
      "2642\n",
      "2643\n",
      "2644\n",
      "3121\n",
      "3122\n",
      "3123\n",
      "3124\n",
      "3125\n",
      "3126\n",
      "3127\n",
      "3128\n",
      "3129\n",
      "3130\n",
      "3131\n",
      "3132\n",
      "3133\n",
      "3134\n",
      "3135\n",
      "3136\n",
      "3137\n",
      "3138\n",
      "3139\n",
      "3140\n",
      "3141\n",
      "3142\n",
      "3143\n",
      "3144\n",
      "3145\n",
      "3146\n",
      "3147\n",
      "3148\n",
      "3149\n",
      "3150\n",
      "3151\n",
      "3152\n",
      "3153\n",
      "3154\n",
      "3155\n",
      "3156\n",
      "3157\n",
      "3158\n",
      "3159\n",
      "3160\n",
      "3161\n",
      "3162\n",
      "3164\n",
      "3166\n",
      "3167\n",
      "3168\n",
      "3169\n",
      "3170\n",
      "3171\n",
      "3172\n",
      "3173\n",
      "3174\n",
      "3179\n",
      "3180\n",
      "3181\n",
      "3182\n",
      "3183\n",
      "3184\n",
      "3185\n",
      "3186\n",
      "3187\n",
      "3188\n",
      "3189\n",
      "3190\n",
      "3191\n",
      "3198\n",
      "3199\n",
      "3202\n",
      "3207\n",
      "3210\n",
      "3211\n",
      "3216\n",
      "3221\n",
      "3226\n",
      "3227\n",
      "3228\n",
      "3231\n",
      "3234\n",
      "3241\n",
      "3243\n",
      "3245\n",
      "3246\n",
      "3247\n",
      "3248\n",
      "3492\n",
      "3493\n",
      "3494\n",
      "3495\n",
      "3496\n",
      "3497\n",
      "3498\n",
      "3612\n",
      "3613\n",
      "3614\n",
      "3615\n",
      "3616\n",
      "3617\n",
      "3618\n",
      "3619\n",
      "3620\n",
      "3621\n",
      "3622\n",
      "3623\n",
      "3626\n",
      "3627\n",
      "3628\n",
      "3640\n",
      "3641\n",
      "3642\n",
      "3643\n",
      "3644\n",
      "3645\n",
      "3646\n",
      "3647\n",
      "3648\n",
      "3649\n",
      "3651\n",
      "3652\n",
      "3653\n",
      "3654\n",
      "3657\n",
      "3662\n",
      "3663\n",
      "3664\n",
      "3665\n",
      "3666\n",
      "3667\n",
      "3670\n",
      "3671\n",
      "3672\n",
      "3673\n",
      "3674\n",
      "3676\n",
      "3680\n",
      "3682\n",
      "3683\n",
      "3684\n",
      "3685\n",
      "3687\n",
      "3689\n",
      "3691\n",
      "3692\n",
      "3693\n",
      "3695\n",
      "3697\n",
      "3700\n",
      "3701\n",
      "3702\n",
      "3706\n",
      "3707\n",
      "3711\n",
      "3712\n",
      "3714\n",
      "3722\n",
      "3723\n",
      "3724\n",
      "3725\n",
      "3726\n",
      "3727\n",
      "3728\n",
      "3729\n",
      "3730\n",
      "3731\n",
      "3732\n",
      "3734\n",
      "3735\n",
      "3736\n",
      "3737\n",
      "3738\n",
      "3739\n",
      "3740\n",
      "3741\n",
      "3742\n",
      "3743\n",
      "3744\n",
      "3745\n",
      "3746\n",
      "3747\n",
      "3748\n",
      "3749\n",
      "3751\n",
      "3752\n",
      "3753\n",
      "3754\n",
      "3755\n",
      "3756\n",
      "3757\n",
      "3758\n",
      "3759\n",
      "3760\n",
      "3761\n",
      "3762\n",
      "3763\n",
      "3764\n",
      "3765\n",
      "3766\n",
      "3767\n",
      "3768\n",
      "3769\n",
      "3770\n",
      "3771\n",
      "3772\n",
      "3773\n",
      "3774\n",
      "3775\n",
      "3776\n",
      "3777\n",
      "3778\n",
      "3779\n",
      "3780\n",
      "3781\n",
      "3782\n",
      "3783\n",
      "3784\n",
      "3785\n",
      "3786\n",
      "3787\n",
      "3788\n",
      "3789\n",
      "3790\n",
      "3791\n",
      "3792\n",
      "3793\n",
      "3794\n",
      "3795\n",
      "3796\n",
      "3797\n",
      "3798\n",
      "3800\n",
      "3801\n",
      "3802\n",
      "3803\n",
      "3804\n",
      "3805\n",
      "3806\n",
      "3807\n",
      "3808\n",
      "3809\n",
      "3810\n",
      "3811\n",
      "3812\n",
      "3813\n",
      "3814\n",
      "3815\n",
      "3816\n",
      "3817\n",
      "3818\n",
      "3819\n",
      "3820\n",
      "3821\n",
      "3825\n",
      "3826\n",
      "3827\n",
      "3828\n",
      "3829\n",
      "3830\n",
      "3831\n",
      "3832\n",
      "3833\n",
      "3834\n",
      "3835\n",
      "3836\n",
      "3837\n",
      "3838\n",
      "3839\n",
      "3840\n",
      "3841\n",
      "3842\n",
      "3843\n",
      "3844\n",
      "3845\n",
      "3846\n",
      "3847\n",
      "3848\n",
      "3849\n",
      "3850\n",
      "3851\n",
      "3852\n",
      "3853\n",
      "3854\n",
      "3855\n",
      "3856\n",
      "3857\n",
      "3858\n",
      "3859\n",
      "3860\n",
      "3861\n",
      "3862\n",
      "3863\n",
      "3864\n",
      "3865\n",
      "3866\n",
      "3867\n",
      "3868\n",
      "3869\n",
      "3870\n",
      "3871\n",
      "3872\n",
      "3873\n",
      "3920\n",
      "3921\n",
      "3922\n",
      "3923\n",
      "3924\n",
      "3925\n",
      "3926\n",
      "3927\n",
      "3928\n",
      "3929\n",
      "3930\n",
      "3931\n",
      "4270\n",
      "4271\n",
      "4272\n",
      "4273\n",
      "4275\n",
      "4276\n",
      "4277\n",
      "4278\n",
      "4279\n",
      "4280\n",
      "4281\n",
      "4282\n",
      "4283\n",
      "4284\n",
      "4285\n",
      "4286\n",
      "4287\n",
      "4288\n",
      "4289\n",
      "4290\n",
      "4291\n",
      "4292\n",
      "4293\n",
      "4294\n",
      "4295\n",
      "4296\n",
      "4297\n",
      "4298\n",
      "4299\n",
      "4300\n",
      "4301\n",
      "4302\n",
      "4303\n",
      "4304\n",
      "4305\n",
      "4307\n",
      "4308\n",
      "4309\n",
      "4310\n",
      "4311\n",
      "4312\n",
      "4313\n",
      "4314\n",
      "4315\n",
      "4316\n",
      "4317\n",
      "4318\n",
      "4319\n",
      "4320\n",
      "4321\n",
      "4322\n",
      "4323\n",
      "4324\n",
      "4325\n",
      "4326\n",
      "4327\n",
      "4328\n",
      "4329\n",
      "4330\n",
      "4331\n",
      "4332\n",
      "4333\n",
      "4334\n",
      "4335\n",
      "4336\n",
      "4337\n",
      "4338\n",
      "4339\n",
      "4344\n",
      "4345\n",
      "4346\n",
      "4347\n",
      "4348\n",
      "4349\n",
      "4350\n",
      "4351\n",
      "4352\n",
      "4353\n",
      "4354\n",
      "4355\n",
      "4356\n",
      "4357\n",
      "4358\n",
      "4359\n",
      "4360\n",
      "4361\n",
      "4362\n",
      "4363\n",
      "4364\n",
      "4365\n",
      "4366\n",
      "4367\n",
      "4368\n",
      "4369\n",
      "4370\n",
      "4371\n",
      "4372\n",
      "4373\n",
      "4374\n",
      "4375\n",
      "4376\n",
      "4377\n",
      "4378\n",
      "4380\n",
      "4381\n",
      "4382\n",
      "4383\n",
      "4384\n",
      "4386\n",
      "4387\n",
      "4388\n",
      "4389\n",
      "4390\n",
      "4391\n",
      "4392\n",
      "4393\n",
      "4394\n",
      "4395\n",
      "4396\n",
      "4397\n",
      "4398\n",
      "0\n",
      "1_x\n",
      "2_y\n",
      "3_x\n",
      "4_x\n",
      "5_x\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10_y\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "1_y\n",
      "2\n",
      "3_y\n",
      "4_y\n",
      "5_y\n"
     ]
    }
   ],
   "source": [
    "for i in data.columns:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5 获得特征提取后的训练集与测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_log = data[data['LABEL'] == 1]  # 获取特征提取后的train_log\n",
    "test_log = data[data['LABEL'] == 0]   # 获取特征提取后的test_log\n",
    "    \n",
    "# 删除train_log、test_log的临时标签\n",
    "del train_log['LABEL']\n",
    "del test_log['LABEL']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_train = pd.merge(train_flg, train_agg, on = ['USRID'], how = 'left')\n",
    "del train_flg\n",
    "del train_agg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.merge(all_train, train_log, on = 'USRID', how = 'left')\n",
    "del train_log\n",
    "del all_train\n",
    "\n",
    "test = pd.merge(test_agg, test_log, on = 'USRID', how = 'left')\n",
    "del test_agg\n",
    "del test_log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1016487 entries, 0 to 1016486\n",
      "Columns: 943 entries, USRID to 5_y\n",
      "dtypes: float64(941), int64(2)\n",
      "memory usage: 7.1 GB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USRID</th>\n",
       "      <th>FLAG</th>\n",
       "      <th>V1</th>\n",
       "      <th>V2</th>\n",
       "      <th>V3</th>\n",
       "      <th>V4</th>\n",
       "      <th>V5</th>\n",
       "      <th>V6</th>\n",
       "      <th>V7</th>\n",
       "      <th>V8</th>\n",
       "      <th>...</th>\n",
       "      <th>19</th>\n",
       "      <th>20</th>\n",
       "      <th>21</th>\n",
       "      <th>22</th>\n",
       "      <th>23</th>\n",
       "      <th>1_y</th>\n",
       "      <th>2</th>\n",
       "      <th>3_y</th>\n",
       "      <th>4_y</th>\n",
       "      <th>5_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.09857</td>\n",
       "      <td>-0.90689</td>\n",
       "      <td>0.86483</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.6308</td>\n",
       "      <td>0.03980</td>\n",
       "      <td>-0.00299</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>0.25427</td>\n",
       "      <td>1.10266</td>\n",
       "      <td>2.10801</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.6308</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>0.25427</td>\n",
       "      <td>1.10266</td>\n",
       "      <td>2.10801</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.6308</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>0.25427</td>\n",
       "      <td>1.10266</td>\n",
       "      <td>2.10801</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.6308</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>0.25427</td>\n",
       "      <td>1.10266</td>\n",
       "      <td>2.10801</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.6308</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 943 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   USRID  FLAG       V1       V2       V3      V4       V5      V6       V7  \\\n",
       "0      0     0  0.09857 -0.90689  0.86483  0.2892 -0.68454 -0.6308  0.03980   \n",
       "1     35     0  0.25427  1.10266  2.10801  0.2892 -0.68454 -0.6308 -0.29641   \n",
       "2     35     0  0.25427  1.10266  2.10801  0.2892 -0.68454 -0.6308 -0.29641   \n",
       "3     35     0  0.25427  1.10266  2.10801  0.2892 -0.68454 -0.6308 -0.29641   \n",
       "4     35     0  0.25427  1.10266  2.10801  0.2892 -0.68454 -0.6308 -0.29641   \n",
       "\n",
       "        V8 ...    19   20   21   22   23  1_y    2   3_y  4_y  5_y  \n",
       "0 -0.00299 ...   NaN  NaN  NaN  NaN  NaN  NaN  NaN   NaN  NaN  NaN  \n",
       "1 -0.18761 ...   0.0  2.0  9.0  0.0  0.0  3.0  9.0  18.0  3.0  0.0  \n",
       "2 -0.18761 ...   0.0  2.0  9.0  0.0  0.0  3.0  9.0  18.0  3.0  0.0  \n",
       "3 -0.18761 ...   0.0  2.0  9.0  0.0  0.0  3.0  9.0  18.0  3.0  0.0  \n",
       "4 -0.18761 ...   0.0  2.0  9.0  0.0  0.0  3.0  9.0  18.0  3.0  0.0  \n",
       "\n",
       "[5 rows x 943 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 257992 entries, 0 to 257991\n",
      "Columns: 942 entries, V1 to 5_y\n",
      "dtypes: float64(941), int64(1)\n",
      "memory usage: 1.8 GB\n"
     ]
    }
   ],
   "source": [
    "test.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>V1</th>\n",
       "      <th>V2</th>\n",
       "      <th>V3</th>\n",
       "      <th>V4</th>\n",
       "      <th>V5</th>\n",
       "      <th>V6</th>\n",
       "      <th>V7</th>\n",
       "      <th>V8</th>\n",
       "      <th>V9</th>\n",
       "      <th>V10</th>\n",
       "      <th>...</th>\n",
       "      <th>19</th>\n",
       "      <th>20</th>\n",
       "      <th>21</th>\n",
       "      <th>22</th>\n",
       "      <th>23</th>\n",
       "      <th>1_y</th>\n",
       "      <th>2</th>\n",
       "      <th>3_y</th>\n",
       "      <th>4_y</th>\n",
       "      <th>5_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-1.92554</td>\n",
       "      <td>-0.90689</td>\n",
       "      <td>-1.26634</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-1.03407</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>-0.50786</td>\n",
       "      <td>-0.60103</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.92554</td>\n",
       "      <td>-0.90689</td>\n",
       "      <td>-1.26634</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-1.03407</td>\n",
       "      <td>0.03980</td>\n",
       "      <td>-0.13652</td>\n",
       "      <td>-0.48351</td>\n",
       "      <td>-0.55402</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.92554</td>\n",
       "      <td>-0.90689</td>\n",
       "      <td>-1.26634</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.09311</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>-0.33740</td>\n",
       "      <td>-0.46000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.92554</td>\n",
       "      <td>-0.90689</td>\n",
       "      <td>-1.26634</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.09311</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>-0.33740</td>\n",
       "      <td>-0.46000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-1.92554</td>\n",
       "      <td>-0.90689</td>\n",
       "      <td>-1.26634</td>\n",
       "      <td>0.2892</td>\n",
       "      <td>-0.68454</td>\n",
       "      <td>-0.09311</td>\n",
       "      <td>-0.29641</td>\n",
       "      <td>-0.18761</td>\n",
       "      <td>-0.33740</td>\n",
       "      <td>-0.46000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 942 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        V1       V2       V3      V4       V5       V6       V7       V8  \\\n",
       "0 -1.92554 -0.90689 -1.26634  0.2892 -0.68454 -1.03407 -0.29641 -0.18761   \n",
       "1 -1.92554 -0.90689 -1.26634  0.2892 -0.68454 -1.03407  0.03980 -0.13652   \n",
       "2 -1.92554 -0.90689 -1.26634  0.2892 -0.68454 -0.09311 -0.29641 -0.18761   \n",
       "3 -1.92554 -0.90689 -1.26634  0.2892 -0.68454 -0.09311 -0.29641 -0.18761   \n",
       "4 -1.92554 -0.90689 -1.26634  0.2892 -0.68454 -0.09311 -0.29641 -0.18761   \n",
       "\n",
       "        V9      V10 ...    19   20   21   22   23  1_y    2  3_y    4_y  5_y  \n",
       "0 -0.50786 -0.60103 ...   NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN    NaN  NaN  \n",
       "1 -0.48351 -0.55402 ...   NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN    NaN  NaN  \n",
       "2 -0.33740 -0.46000 ...   0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0  105.0  0.0  \n",
       "3 -0.33740 -0.46000 ...   0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0  105.0  0.0  \n",
       "4 -0.33740 -0.46000 ...   0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0  105.0  0.0  \n",
       "\n",
       "[5 rows x 942 columns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输出特征提取后的train、test数据\n",
    "train.to_csv(path + '/features/train.csv', sep = '\\t', index = None)\n",
    "test.to_csv(path + '/features/test.csv', sep = '\\t', index = None)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
